<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="../CssFrame/bootstrap.css">

<script src="../Jquery/Jquery-3.3.1.js" type="text/javascript"></script>

<meta charset="UTF-8">
<title>修改住宿生资料</title>
</head>
<body>
	<div style="text-align: center;">
		<form id="stud_form" style="margin-top: 42px;">
			<p>学号(不可修改)</p>
			<br> <input type="text" name="studentNo" placeholder="" class="inputclass0" readonly="readonly">

			<p>请输入新的姓名</p>
			<br> <input type="text" name="studentName" placeholder="" class="inputclass00"> <br> <br>

			<!--  -->
			<p>请输入新的楼栋编号</p>
			<br> <input type="text" name="buildingNo" placeholder="" class="inputclass01" maxlength="2"> <br> <br>
			<!--  -->
			<p>请输入新的寝室编号</p>
			<br> <input type="text" name="chamberNo" placeholder="" class="inputclass02" maxlength="4"> <br> <br>

			<!--  -->
			<div>
				<input type="button" class="btn btn-primary" value="确定" id="sub_commit" onclick="stdDoEdit()"
					style="margin-right: 20px;">
				<!--  -->
				<input type="button" class="btn btn-primary" value="重置" id="sub_reset" style="margin-left: 20px;">
			</div>

		</form>

		<!--  -->
		<div style="margin-top: 36px;">
			<a href="DormitoryManageSystem.html">返回系统导航页</a>
		</div>

	</div>
</body>

<script type="text/javascript">
	$(document).ready(function() {
		showEidtStud();
	});

	function showEidtStud() {
		var url = "/dormitory/Students/show_will_edit_stud";
		$.ajax({
			url : url,
			type : "GET",
			contentType : "application/json;cherset=utf-8",
			dataType : "json",
			success : function(j) {
				if (j.state == 200) {
					$('.inputclass0').val(j.data.studentNo);
					$('.inputclass00').attr('placeholder', j.data.studentName);
					$('.inputclass01').attr('placeholder', j.data.buildingNo);
					$('.inputclass02').attr('placeholder', j.data.chamberNo);
				} else {
					console.log(j.message);
				}
			}
		});
	}

	/* 发往后台修改资料 */
	function stdDoEdit() {
		var url = "/dormitory/Students/exe_edit_stud";
		var data = $("#stud_form").serialize();
		$.ajax({
			"url" : url,
			"data" : data,
			"type" : "POST",
			"dataType" : "json",
			"success" : function(json) {
				if (json.state == 200) {
					alert("修改成功");
					location.href = "StudentList.html";
				} else {
					alert(json.message);
				}
			}
		});
	}

	/* 重置 */
	$('#sub_reset').click(function() {
		$(".inputclass00").val('')
		$(".inputclass01").val('')
		$(".inputclass02").val('')
	});
</script>
</html>